package com.menggudf.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.menggudf.model.ResultModel;
import com.menggudf.service.PartService;

@RequestMapping("/part")
@Controller
public class PartController {
    
    @Autowired
    PartService partService;

    @RequestMapping("/addPart")
    @ResponseBody
    public ResultModel addPart(
            @RequestParam("oneNum") Integer oneNum,
            @RequestParam("twoNum") Integer twoNum,
            @RequestParam("onePart") String onePart,
            @RequestParam("twoPart") String twoPart){
                return partService.addPart(onePart, twoPart,oneNum,twoNum);
        
    }
    
    @RequestMapping("/editPart")
    @ResponseBody
    public ResultModel editPart(
            @RequestParam("id") Integer id,
            @RequestParam(value="onePart",required=false) String onePart,
            @RequestParam(value="twoPart",required=false) String twoPart,
            @RequestParam(value="oneNum",required=false) Integer oneNum,
            @RequestParam(value="twoNum",required=false) Integer twoNum){
                return partService.eidtPart(id, onePart, twoPart,oneNum,twoNum);
        
    }
    
    @RequestMapping("/deletePart")
    @ResponseBody
    public ResultModel deletePart(
            @RequestParam("id") Integer id){
                return partService.deletePart(id);
        
    }
    
    @RequestMapping("/queryAllPartGroups")
    @ResponseBody
    public Map<String, Object> queryPartList(
            @RequestParam(value="onePart",required=false) String onePart,
            @RequestParam(value="twoPart",required=false) String twoPart,
            @RequestParam("limit") int pageSize,
            @RequestParam("offset") int offset){
                return partService.queryAllPartGroups(onePart,twoPart,pageSize,offset);
        
    }
}
